<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/11/29
 * Time: 17:22
 */
namespace common\sources\read\adminuser;

use common\models\craftsman\AdminUser;

class AdminUserAccess implements IAdminUserAccess
{
	//TODO:: 已弃用 改为 getDetial
    public function getAdminUser($phone)
    {
        return AdminUser::find()
                ->select('id,pwd,role,username,phone')
                ->where(['phone'=>$phone])
                ->asArray()
                ->one();
    }

    // 根据手机号查询 管理员信息
	public function getDetial($account) {
		return AdminUser::find()
			->select("id,create_time,role,username,phone,email")
			->where(["phone" => $account])
			->asArray()
			->one();
	}

    public function getLoginUserById($login_id)
    {
        return AdminUser::find()
            ->select("id,create_time,role,username,phone,email")
            ->where(["id" => $login_id])
            ->asArray()
            ->one();
    }

    //获取管理员列表
    public function getList()
    {
        return AdminUser::find()
            ->select("id,create_time,role,username,phone,email")
            ->asArray()
            ->all();
    }

    //搜索管理员 TODO:: 已弃用 改为 getDetial
    public function searchWorker($phone)
    {
        return AdminUser::find()
            ->select("id,create_time,role,username,phone,email")
            ->where(["phone" => $phone])
            ->asArray()
            ->one();
    }

	/**
	 * getRoleUserList 根据角色获取用户列表
	 * @param $where 条件
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/15
	 * @return array|\yii\db\ActiveRecord[]
	 */
    public function getRoleUserList($where){
	    return AdminUser::find()
		    ->select("id,create_time,role,username,phone,email")
		    ->where($where)
		    ->asArray()
		    ->all();
    }

}